package co.gov.mintic.Biblioteca.android;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;

public class DescargarLibro extends ImageButton {

	private String source;

	public DescargarLibro(Context context) {
		super(context);
	}

	public DescargarLibro(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public DescargarLibro(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public void init(final Activity activity) {
		setBackgroundColor(Color.TRANSPARENT);
		setOnClickListener(new ButtonOnClickListener(activity));
	}

	private final class ButtonOnClickListener implements OnClickListener {

		Activity activity;

		public ButtonOnClickListener(Activity activity) {

			this.activity = activity;
		}

		@Override
		public void onClick(View arg0) {

			Intent browserIntent = new Intent(Intent.ACTION_VIEW,
					Uri.parse(source.toLowerCase()));
			activity.startActivity(browserIntent);
		}
	}

	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	/**
	 * @param source
	 *            the source to set
	 */
	public void setSource(String source) {
		this.source = source;
	}
}
